#include "hsp3_64.as" #include "hspdsc64.as" title "DirectShow キャプチャデバイス表示(MP4ファイルで保存)" cls 4 dsc_Init // 初期化 // デバイスリスト用の変数を初期化 sdim devlist, dsc_GetDeviceListSize() // デバイスリストを変数に格納 dsc_GetDeviceList devlist, 0 if stat == 0 || stat == -2 : dialog "デバイスが見つかりません" : end objsize 300, 20 combox did, 100, devlist objsize 150,20 button "映像をMP4に保存",*save button gosub "デバイスを停止",*_stop button gosub "終了する",*exit onexit gosub *exit // エンコーダー初期化 dsc_InitEncoder stop *save once = 0 // キャプチャ処理 dsc_SetActiveSel 0 dsc_Open did, 2, 0, 1, 1 if stat < 0 : dialog "エラーが発生しました。("+stat+")",1,"DEVICE-ERROR" : stop dsc_Play hwnd, 160, 120, 320, 240 if stat < 0 : dialog "エラーが発生しました。",1,"CAPTURE-ERROR" : stop // 読み取り本体 repeat await 33 // 大体 30fps ぐらい // 下準備 sdim dibdata, dsc_GetImageMemSize(0) sdim dibhead, dsc_GetImageMemSize(1) dibsize = dsc_GetImageMemSize(0) // カメラからキャプチャ dsc_GetImageMem dibdata, dibsize, dibhead x = lpeek(dibhead, 4) // 幅 y = lpeek(dibhead, 8) // 高さ if ( x == 0 || y == 0 ) : continue // サイズが 0 // 1回のみ実行 if once == 0 { // エンコーダーを作成する id_enc = dsc_CreateEncoder() dsc_OpenEncoder id_enc, dir_cur + "\\test.mp4", 2, x, y, 24, 1000.0 / 33, 3000000 once = 1 } // キャプチャした 1フレームをエンコーダーに渡す dsc_WriteEncoder id_enc, dibdata, 0 loop stop *_stop // エンコード処理終了 dsc_CloseEncoder id_enc dsc_DeleteEncoder id_enc // 停止&クローズ dsc_Stop dsc_Close return *exit gosub *_stop dsc_UnInitEncoder end